﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;

namespace SPPTesteGeral.VWPFormLogin
{
    public partial class VWPFormLoginUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            SPWeb myWeb = SPContext.Current.Site.RootWeb;
            SPList myList = myWeb.Lists["Usuario"];

            SPQuery myQuery = new SPQuery();
            myQuery.Query = string.Format(@"<Where><And>
                                <Eq><FieldRef Name='Title' />
                                    <Value Type='Text'>{0}</Value></Eq>
                                <Eq><FieldRef Name='Senha' />
                                    <Value Type='Text'>{1}</Value></Eq>
                                </And></Where>", txtNome.Text.Trim(), txtSenha.Text.Trim());

            SPListItemCollection mycollection = myList.GetItems(myQuery);
            if (mycollection != null) lblMsg.Text = (mycollection.Count > 0) ? "Usuario logado" : "Usuario não Logado";
            else lblMsg.Text = "Usuario não cadastrado";
        }
    }
}
